<!DOCTYPE html>
<html lang="en">
<head>
    <meta charset="UTF-8">
    <meta name="viewport" content="width=device-width, initial-scale=1.0">
    <title>Document</title>
</head>
<body>

    <script>

        const worker = new Worker('./workerByClose.js',{name:'worker1'});

        // 向worker发送消息
        worker.postMessage('hello');

        // 监听worker返回的消息,两种监听都可以
        // worker.addEventListener('message',(e)=> {})
        worker.onmessage = function(event){
            console.log(event.data);
        }

    </script>
    
</body>
</html>